package com.tuoyu.peopletest.view.custom;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.tuoyu.peopletest.R;


@SuppressLint("AppCompatCustomView")
public class MyIconSelectImageView extends ImageView {

    private int     nomalBitmap;
    private int     selectBitmap;
    private boolean isSelect;

    public MyIconSelectImageView(Context context) {
        this(context, null);
    }

    public MyIconSelectImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyIconSelectImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable
                .MyIconSelectImageView);

        if (a != null) {

            nomalBitmap = a.getResourceId(R.styleable.MyIconSelectImageView_nomal_image, 0);
            selectBitmap = a.getResourceId(R.styleable.MyIconSelectImageView_select_image, 0);
            isSelect = a.getBoolean(R.styleable.MyIconSelectImageView_is_select, false);
            a.recycle();
        }


        setImage();

    }

    public void setImage() {
        if (isSelect) {
            setImageResource(selectBitmap);
        } else {
            setImageResource(nomalBitmap);
        }
    }

    public void setImage02() {
        if (isSelect) {
            setRotation(180);
            setImageResource(selectBitmap);
        } else {
            setRotation(0);
            setImageResource(nomalBitmap);
        }
    }


    public boolean isSelect(){
        return isSelect;
    }

    public void setSelect(boolean isSelect){
        this.isSelect = isSelect;
        setImage();
    }

    public void setSelect02(boolean isSelect){
        this.isSelect = isSelect;
        setImage02();
    }
}
